package com.soft.mybatis.mapper;

import com.soft.mybatis.entity.Items;
import com.soft.mybatis.entity.OrderDetail;
import com.soft.mybatis.entity.Orders;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrderDetailMapper {
    //作业1：根据订单明细，关联查询商品信息
    OrderDetail getOrderDetailAndItemById(Integer id);

    //作业2：根据订单明细，关联查询订单信息
    OrderDetail getOrderDetailAndOrderById(Integer id);

    //注解方式作业2：每个订单中包含的商品信息 OM
    @Select("select * from orderdetail where orders_id = #{id}")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "ordersId",column = "orders_id"),
            @Result(property = "itemsId",column = "items_id"),
            @Result(property = "itemsNum",column = "items_num"),
            @Result(property = "items",column = "items_id",javaType = Items.class,
                    one = @One(select = "com.soft.mybatis.mapper.ItemsMapper.selectItem"))
    })
    List<OrderDetail> selectOrderDetailAndItemById(Integer id);
}
